import 'dart:convert';

import 'package:flutter_pleasure_video/util/string_util.dart';

/// title : "spankbang"
/// author : "TyrantGenesis"
/// url : "https://spankbang.com/fyclass/fypage/"
/// version : 1
/// col_type : ""
/// class_name : "最新&热门&最受欢迎"
/// class_url : "new_videos&trending_videos&most_popular"
/// area_name : ""
/// area_url : ""
/// sort_name : ""
/// year_name : ""
/// sort_url : ""
/// year_url : ""
/// find_rule : "js: let res = {}; let d = []; const html = getResCode(); const list = parseDomForArray(html, '.video-list&&.video-item'); list.forEach(item => { d.push({ title: parseDomForHtml(item, '.name&&Text'), desc: parseDomForHtml(item, '.l&&Text'), pic_url: parseDom(item, '.cover&&data-src'), url: parseDom(item,'a&&href'), col_type: 'movie_3', }); }) res.data = d; setHomeResult(res);"
/// search_url : "https://spankbang.com/s/**/fypage/"
/// titleColor : "#ffd166"
/// group : "⑩GHS"
/// searchFind : "js: let res = {}; let d = []; const html = getResCode(); const list = parseDomForArray(html, '.video-list&&.video-item'); list.forEach(item => { d.push({ title: parseDomForHtml(item, '.name&&Text'), desc: parseDomForHtml(item, '.l&&Text'), pic_url: parseDom(item, '.cover&&data-src'), url: parseDom(item,'a&&href'), }); }) res.data = d; setHomeResult(res);"
/// detail_col_type : ""
/// detail_find_rule : "js: let res = {}; let d = []; const html = getResCode(); const script = parseDomForHtml(html, '#inner_content&&script&&Html'); eval(script) d.push({ pic_url: stream_data.cover_image, col_type: 'pic_1' }); if (stream_data['240p'].length > 0) { d.push({ title: '240p', url: stream_data['240p'][0], col_type: 'text_2' }); } if (stream_data['320p'].length > 0) { d.push({ title: '320p', url: stream_data['320p'][0], col_type: 'text_2' }); } if (stream_data['480p'].length > 0) { d.push({ title: '480p', url: stream_data['480p'][0], col_type: 'text_2' }); } if (stream_data['720p'].length > 0) { d.push({ title: '720p', url: stream_data['720p'][0], col_type: 'text_2' }); } if (stream_data['1080p'].length > 0) { d.push({ title: '1080p', url: stream_data['1080p'][0], col_type: 'text_2' }); } if (stream_data['4k'].length > 0) { d.push({ title: '4k', url: stream_data['480p'][0], col_type: 'text_2' }); } res.data = d; setHomeResult(res);"
/// sdetail_col_type : "movie_1"
/// sdetail_find_rule : "js: let res = {}; let d = []; const html = getResCode(); const script = parseDomForHtml(html, '#inner_content&&script&&Html'); eval(script) d.push({ pic_url: stream_data.cover_image, col_type: 'pic_1' }); if (stream_data['240p'].length > 0) { d.push({ title: '240p', url: stream_data['240p'][0], col_type: 'text_2' }); } if (stream_data['320p'].length > 0) { d.push({ title: '320p', url: stream_data['320p'][0], col_type: 'text_2' }); } if (stream_data['480p'].length > 0) { d.push({ title: '480p', url: stream_data['480p'][0], col_type: 'text_2' }); } if (stream_data['720p'].length > 0) { d.push({ title: '720p', url: stream_data['720p'][0], col_type: 'text_2' }); } if (stream_data['1080p'].length > 0) { d.push({ title: '1080p', url: stream_data['1080p'][0], col_type: 'text_2' }); } if (stream_data['4k'].length > 0) { d.push({ title: '4k', url: stream_data['480p'][0], col_type: 'text_2' }); } res.data = d; setHomeResult(res);"
/// ua : "mobile"
/// preRule : ""

class YckRuleModel {
  String? id;
  String? _title;
  String? _author;
  String? _url;
  int? _version;
  String? _colType;
  String? _className;
  String? _classUrl;
  String? _areaName;
  String? _areaUrl;
  String? _sortName;
  String? _yearName;
  String? _sortUrl;
  String? _yearUrl;
  String? _findRule;
  String? _searchUrl;
  String? _titleColor;
  String? _group;
  String? _searchFind;
  String? _detailColType;
  String? _detailFindRule;
  String? _sdetailColType;
  String? _sdetailFindRule;
  String? _ua;
  String? _preRule;
  int? _addTime;

  String get title => _title??"";
  String get author => _author??"";
  String get url => _url??"";
  int get version => _version??0;
  String get colType => _colType??"";
  String get className => _className??"";
  String get classUrl => _classUrl??"";
  String get areaName => _areaName??"";
  String get areaUrl => _areaUrl??"";
  String get sortName => _sortName??"";
  String get yearName => _yearName??"";
  String get sortUrl => _sortUrl??"";
  String get yearUrl => _yearUrl??"";
  String get findRule => _findRule??"";
  String get searchUrl => _searchUrl??"";
  String get titleColor => _titleColor??"";
  String get group => _group??"";
  String get searchFind => _searchFind??"";
  String get detailColType => _detailColType??"";
  String get detailFindRule => _detailFindRule??"";
  String get sdetailColType => _sdetailColType??"";
  String get sdetailFindRule => _sdetailFindRule??"";
  String get ua => _ua??"";
  String get preRule => _preRule??"";
  int get addTime => _addTime??DateTime.now().millisecondsSinceEpoch;

  YckRuleModel({
      String? id,
      String? title,
      String? author,
      String? url,
      int? version,
      String? colType,
      String? className,
      String? classUrl,
      String? areaName,
      String? areaUrl,
      String? sortName,
      String? yearName,
      String? sortUrl,
      String? yearUrl,
      String? findRule,
      String? searchUrl,
      String? titleColor,
      String? group,
      String? searchFind,
      String? detailColType,
      String? detailFindRule,
      String? sdetailColType,
      String? sdetailFindRule,
      String? ua,
      String? preRule,
      int? addTime,
  }){
    this.id = id;
    _title = title;
    _author = author;
    _url = url;
    _version = version;
    _colType = colType;
    _className = className;
    _classUrl = classUrl;
    _areaName = areaName;
    _areaUrl = areaUrl;
    _sortName = sortName;
    _yearName = yearName;
    _sortUrl = sortUrl;
    _yearUrl = yearUrl;
    _findRule = findRule;
    _searchUrl = searchUrl;
    _titleColor = titleColor;
    _group = group;
    _searchFind = searchFind;
    _detailColType = detailColType;
    _detailFindRule = detailFindRule;
    _sdetailColType = sdetailColType;
    _sdetailFindRule = sdetailFindRule;
    _ua = ua;
    _preRule = preRule;
    _addTime = addTime;
}

  YckRuleModel.fromJson(dynamic json,[String? id]) {
    _title = json["title"];
    _author = json["author"];
    _url = json["url"];
    _version = json["version"];
    _colType = json["col_type"];
    _className = json["class_name"];
    _classUrl = json["class_url"];
    _areaName = json["area_name"];
    _areaUrl = json["area_url"];
    _sortName = json["sort_name"];
    _yearName = json["year_name"];
    _sortUrl = json["sort_url"];
    _yearUrl = json["year_url"];
    _findRule = json["find_rule"];
    _searchUrl = json["search_url"];
    _titleColor = json["titleColor"];
    _group = json["group"];
    _searchFind = json["searchFind"];
    _detailColType = json["detail_col_type"];
    _detailFindRule = json["detail_find_rule"];
    _sdetailColType = json["sdetail_col_type"];
    _sdetailFindRule = json["sdetail_find_rule"];
    _ua = json["ua"];
    _preRule = json["preRule"];
    if(id!=null||json["id"]!=null) {
      this.id = id??json["id"];
    }else{
      this.id=StringUtil.getMd5(_url) + StringUtil.getMd5(_title);
    }
    if(json["addTime"]!=null) {
      _addTime = json["addTime"];
    }else{
      _addTime=DateTime.now().millisecondsSinceEpoch;
    }
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map["id"] = this.id;
    map["title"] = _title;
    map["author"] = _author;
    map["url"] = _url;
    map["version"] = _version;
    map["col_type"] = _colType;
    map["class_name"] = _className;
    map["class_url"] = _classUrl;
    map["area_name"] = _areaName;
    map["area_url"] = _areaUrl;
    map["sort_name"] = _sortName;
    map["year_name"] = _yearName;
    map["sort_url"] = _sortUrl;
    map["year_url"] = _yearUrl;
    map["find_rule"] = _findRule;
    map["search_url"] = _searchUrl;
    map["titleColor"] = _titleColor;
    map["group"] = _group;
    map["searchFind"] = _searchFind;
    map["detail_col_type"] = _detailColType;
    map["detail_find_rule"] = _detailFindRule;
    map["sdetail_col_type"] = _sdetailColType;
    map["sdetail_find_rule"] = _sdetailFindRule;
    map["ua"] = _ua;
    map["preRule"] = _preRule;
    map["addTime"] = _addTime;
    return map;
  }

  String toString(){
    return jsonEncode(toJson());
  }
}